<?php
defined('BASEPATH') OR exit('No direct script access allowed');


/**
*   前台用户的操作
 */
class Member extends Base_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("member_model");
    }

    /**
     *   测试用户登录成功
     */
    public function index()
    {
        echo 'userid:'.$this->userid.'--username:'.$this->username;
        echo "<br>";
        echo '<a href="/member/logout/">退出</a>';
        exit();
    }

    /**
    *   用户登录
     */
	public function login()
	{
        if($this->is_post()){
            $username = $this->input->post('username', true);
            $password = $this->input->post('password', true);
            $result = array("state" => true, 'url'=>'/member/index' );
            if(!($this->member_model->login( $username, $password ))) {
                $result = array("state" => false, "error" => $this->member_model->error() );
            }
            if($this->is_ajax()){
                echo  json_encode($result);
                exit();
            }
            redirect( '/member/index/' );
        }
        if($this->userid){
            redirect( '/member/index/' );
        }
        $this->load->view('member/login');
	}



    /**
     *  用户退出
     */
    public function logout()
    {
        $this->member_model->logout();
        redirect( '/' );
    }


    /**
     *  用户详细信息
     */
    public function user_detail()
    {

    }


    /**
     *  用户注册
     */
    public function reg()
    {
        if($this->is_post()){
            $result = array("state" => true, 'url'=>'/member/index' );
            $data['username'] = $this->input->post('username', true);
            $data['password'] = $this->input->post('password', true);
            $data['email']    = $this->input->post('email', true);
            if(!($this->member_model->register( $data ))) {
                $result = array("state" => false, "error" => $this->member_model->error() );
            }
            if($this->is_ajax()){
                echo  json_encode($result);
                exit();
            }
            redirect( '/member/index/' );
        }
        if($this->userid){
            redirect( '/member/index/' );
        }
        $this->load->view('member/register');
    }


    /**
     *  投稿列表
     */
    public function article_list()
    {

    }

    /**
     *  投稿操作
     */
    public function article_contribute()
    {

    }



    /**
     *  投稿保存
     */
    public function article_save()
    {

    }





}
